package ar.com.utn.openqsb.lip;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JDesktopPane;

import ar.com.utn.openqsb.commons.Module;
import ar.com.utn.openqsb.lip.ui.ExerciseFrame;
import ar.com.utn.openqsb.lip.ui.MenuBarFactory;

/**
 * Linear and Integer Programming module launcher.
 * 
 * @author rvega
 * 
 */
public class LIPModule extends Module {

	private static final long serialVersionUID = -6626887670473716756L;

	private JDesktopPane dp;

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void launch() {
		setVisible(true);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void prepare() {
		// set default size and position of the screen
		setPreferredSize(new Dimension(800, 560));
		setMinimumSize(new Dimension(800, 560));
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2);

		// create inner desktop
		dp = new JDesktopPane();
		add(dp, BorderLayout.CENTER);

		// Create menu
		MenuBarFactory.createMenu(this, dp);

		// Make dragging a little faster but perhaps uglier.
		dp.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);

		pack();
	}

	public void newWindow(String exerciseId) {
		ExerciseFrame frame = new ExerciseFrame(exerciseId);
		dp.add(frame);
		frame.launch();
	}
}
